﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Detail.master" AutoEventWireup="true" CodeFile="productDetail.aspx.cs" Inherits="company_productDetail" %>

<%@ Register src="../UserControls/UC_Category.ascx" tagname="UC_Category" tagprefix="uc1" %>
<%@ Import Namespace="Back.Xinkui.Common.Enum" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headcss" Runat="Server">
<link href="/themes/default/css/layer.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<fieldset>
<legend>Product Detail</legend>
<table class="editTable" border="1" cellspacing="1" cellpadding="0" style="width: 100%;">
<tr>
    <th>Product Name：</th>
    <td colspan="3"><asp:TextBox ID="txtProdcutName" runat="server" CssClass="inputText" MaxLength="150"></asp:TextBox> </td>
</tr>
<tr>
    <th>Category：</th>
    <td colspan="3">
      <uc1:UC_Category ID="UC_Category1" runat="server" />
    </td>
</tr>
<tr>
    <th>Main Keywords：</th>
    <td><asp:TextBox ID="txtMainKeyWord" runat="server" CssClass="inputText" MaxLength="100"></asp:TextBox> </td>
    <th>Keywords：</th>
    <td><asp:TextBox ID="txtKeyWord" runat="server" CssClass="inputText" MaxLength="500"></asp:TextBox> </td>
</tr>
<tr>
    <th>Place Of Origin：</th>
    <td><asp:TextBox ID="txtPlaceOfOrigin" runat="server" CssClass="inputText" MaxLength="200"></asp:TextBox> </td>
    <th>CertificateIDS</th>
    <td><asp:TextBox ID="txtCertificateg" runat="server" CssClass="inputText" MaxLength="200"></asp:TextBox> </td>
</tr>
<tr>
    <th>KeyProducts：</th>
    <td colspan="3"><asp:RadioButton ID="radioYes" runat="server" Text="Yes" GroupName="KeyProducts" /> 
    <asp:RadioButton ID="radioNo" runat="server" Text="No" GroupName="KeyProducts" /></td>
</tr>
<tr>
    <th>Application：</th>
    <td colspan="3"><asp:TextBox ID="txtApplication" runat="server" CssClass="inputText"></asp:TextBox> </td>
</tr>
<tr>
    <th>OEMNO：</th>
    <td colspan="3"><asp:TextBox ID="txtOem" runat="server" CssClass="inputText" MaxLength="150"></asp:TextBox> </td>
</tr>
<tr>
    <th>Description：</th>
    <td colspan="3"><asp:TextBox ID="txtDescription" runat="server" CssClass="inputText" TextMode="MultiLine" Rows="5"></asp:TextBox> </td>
</tr>
<tr>
    <th>Image：</th>
    <td><%--<%=imgProduct%><input type="button" value="upload" style="width:80px;" />--%>
        <asp:HiddenField ID="hidLogo" runat="server" />
        <asp:Image ID="viewImg" runat="server" ImageUrl="~/Themes/default/images/Img/noimage.jpg" Width="100" />
        <%--<img src="/Themes/default/images/Img/noimage.jpg" id="viewImg" width="100" />--%>
        <a href="javascript:" onclick="uploadImg(<%=(int)Xinkui.Common.Enum.ESourceType.FromProductImage%>)">上传</a>
    </td>
</tr>
</table>
<div style="text-align:center;">
    <%if (ProductId > 0 && AuditStatus != (int)EAuditStatus.Approve){ %>
    <asp:Button ID="btnApprove" runat="server" Text="Approve" CssClass="btn" 
        onclick="btnApprove_Click" />
        <%} %>
    <%if (AuditStatus != (int)EAuditStatus.Reject){ %>
    <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="btn" 
        onclick="btnSave_Click" OnClientClick="return CheckProduct();" />
        <%} %>
    <%if (ProductId > 0 && AuditStatus != (int)EAuditStatus.Reject){ %>
    <asp:Button ID="btnReject" runat="server" Text="Reject" CssClass="btn" 
        onclick="btnReject_Click" />
        <%} %>
    <input type="button" value="Close" onclick="window.close();" class="btn" />
</div>
</fieldset>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script type="text/javascript">
    $(function () {
        $(".proSelect").change(function () {
            loadCategory($(this), 1);
        });
    });

    function loadCategory(obj,index) {
        $.ajax({
            url: "/handlers/CategoryHandler.ashx",
            dataType: 'json',
            data: { cId: $(obj).val() },
            type: 'post',
            success: function (value) {
                if (value.length == 0) {
                    $("#hidCaegory").val($(obj).val());

                    var className = ".proSelect" + index
                    $(className).remove();
                } else {
                    $("#hidCaegory").val("");
                    var html = '<select class="proSelect' + index + '" size="10">';
                    for (var i = 0; i < value.length; i++) {

                        html += '<option value="' + value[i]['id'] + '">' + value[i]['cname'] + '</option>';
                    }
                    html += '</select>';

                    $('.proSelect' + index).remove();
                    $('.proSelect' + (index + 1)).remove();
                    $(obj).after(html);

                    $('.proSelect' + index).change(function () {
                        loadCategory($(this), index + 1);
                    });
                }

                for (var i = index; i >= 0; i--) {

                    var textCategory = $(".proSelect" + i).find("option:selected").text();
                    if (i == 0) {
                        textCategory = $(".proSelect").find("option:selected").text();
                    }

                    if (i == index-1) {
                        $("#txtCategory").text(textCategory);
                    } else {
                        $("#txtCategory").text(textCategory + ">>" + $("#txtCategory").text());
                    }
                }
            },
            error: function () {
                alert('error');
            }
        });
    }
    //验证产品信息
    function CheckProduct() {
        var proName = $("#<%=txtProdcutName.ClientID%>").val();
        if (proName == null || proName == "") {
            alert("ProdcutName is null!");
            return false;
        }
        var category = $("#hidCaegory").val();
        if (category == null || category == "" || category=="0") {
            alert("Please select Category!");
            return false;
        }
        var mainKey = $("#<%=txtMainKeyWord.ClientID%>").val();
        if (mainKey == null || mainKey == "") {
            alert("Main Keywords is null!");
            return false;
        }
        var pic = $("#<%=hidLogo.ClientID%>").val();
        if (pic == null || pic == "") {
            alert("Please upload picture!");
            return false;
        }
        return true;
    }

    function uploadImg(sType) {
        OpenWindow("/Upload.aspx?sType=" + sType, 300, 50);
    }
    function uploadSuccess(varFile) {
        switch (varFile.SourceType) {
            case 3:
                uploadProductImg(varFile);
                break;
        }
    }
    function uploadProductImg(varFile) {
        $("#<%=viewImg.ClientID%>").attr("src", varFile.ImageUrl);
        $("#<%=hidLogo.ClientID%>").val(varFile.SavePath);
    }
</script>
</asp:Content>

